package cn.com.zero.base.vo;

import cn.com.zero.base.constant.ZeroConstants;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.lang.Nullable;

/**
 * @author zhoupeng
 * @version 1.0.0
 * @Description
 * @createTime 2022-07-11
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseVO extends BaseVO {

    /**
     * 返回码
     */
    private long code;

    /**
     * 消息
     */
    private String message;

    /**
     * 返回数据
     */
    private Object data;

    /**
     * 返回消息参数
     */
    @JsonIgnore
    private String[] args;

    public static ResponseVO newInstance(long code, @Nullable String message, @Nullable Object data, @Nullable String[] args) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setCode(code);
        responseVO.setMessage(message);
        responseVO.setData(data);
        responseVO.setArgs(args);
        return responseVO;
    }

    public static ResponseVO success(@Nullable Object data) {
        return newInstance(ZeroConstants.RETURN_CODE_SUCCESS, null, data, null);
    }

    public static ResponseVO success(long code, @Nullable Object data) {

        return newInstance(code, null, data, null);
    }

    public static ResponseVO error(long code) {
        return newInstance(code, null, null, null);
    }

    public static ResponseVO error(long code, @Nullable String... args) {

        return newInstance(code, null, null, args);
    }

    public long getCode() {
        return code;
    }

    public void setCode(long code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String[] getArgs() {
        return args;
    }

    public void setArgs(String[] args) {
        this.args = args;
    }
}
